<template>
	<div>
		<!-- <div class="h2">学生组织申请加入管理</div> -->
		<a-button-group size="default" class="option">
			<a-button type="primary" @click="addList">新增</a-button>
		</a-button-group>
		<div>
			<el-table stripe :data="data" v-loading="loading" border :max-height="tableHeight" highlight-current-row style="width: 100%;">
				<el-table-column type="index" label="序号" width="60" fixed="left"></el-table-column>
				<el-table-column prop="Name" label="名称" min-width="100"></el-table-column>
				<!-- <el-table-column prop="TypeName" label="表单类型" min-width="100"></el-table-column -->>
				<el-table-column prop="FieldType" label="字段类型" min-width="100">
					<template slot-scope="scope">
						<a-tag color="blue">{{ FieldTypeList.filter(item => item.Key == scope.row.FieldType).length>0?FieldTypeList.filter(item => item.Key == scope.row.FieldType)[0].Value:'' }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="IsShow" label="是否前台显示" min-width="100" >
					<template slot-scope="scope">
						<a-tag :color="scope.row.IsShow ? 'green' : 'pink'">{{ scope.row.IsShow?'显示':'不显示' }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="IsMust" label="是否必填" min-width="100">
					<template slot-scope="scope">
						<a-tag :color="scope.row.IsMust ? 'green' : 'pink'">{{ scope.row.IsMust?'必填':'非必填' }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="Regular" label="正则验证/选择项" min-width="220"></el-table-column>
				<el-table-column prop="ErroeMsg" label="验证失败提示" min-width="100"></el-table-column>
				<el-table-column label="操作" width="150" fixed="right">
					<template slot-scope="scope">
						<a-tooltip placement="top">
							<template slot="title">修改</template>
							<i title="修改" class="iconfont icon-editor1" style="color: #1890FF;" @click="modifyList(scope.row, 'modify')"></i>
						</a-tooltip>
						<a-tooltip placement="top">
							<template slot="title">删除</template>
							<i title="删除" class="iconfont icon-delete" style="color: red;" @click="deleteList(scope.row)"></i>
						</a-tooltip>
						<a-tooltip placement="top" v-if="scope.$index!=0">
							<template slot="title">升序</template>
							<i title="升序" class="iconfont icon-paixu1" style="color: green;" @click="sortList(scope.row,1)"></i>
						</a-tooltip>
						<a-tooltip placement="top" v-if="scope.$index!=data.length-1">
							<template slot="title">降序</template>
							<i title="降序" class="iconfont icon-paixu" style="color: brown;" @click="sortList(scope.row,2)"></i>
						</a-tooltip>
					</template>
				</el-table-column>
			</el-table>
		</div>
		<add :text="text" :type="typeCurrent" v-show="addIf" :FieldTypeList="FieldTypeList" @closeFun="closeFun"></add>
	</div>
</template>


<script>
	import add from './add.vue';
	import Func from '@/utils/func';
	import Cache from '@/utils/cache';
	import {
		ManageApplyClubFormList,
		UserApplyClubFormList,
		DoDeleteManageApplyClubForm,
		DoDeleteUserApplyClubForm,
		DoSortManageApplyClubForm,
		DoSortUserApplyClubForm,
		GetApplyFormFieldTypeList
	} from '@/api/follow';
	const data = [];
	export default {
		components: {
			add
		},
		props:{
			typeCurrent:Number
		},
		data() {
			return {
				data,
				form: this.$form.createForm(this, {
					name: 'advanced_search'
				}),
				pagination: {
					currentPage: 1,
					pageSize: this.global.pageSize,
					pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
					showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
				},
				addIf: false,
				text: {},
				visible: false,
				confirmLoading: false,
				itemId: '',
				departmentList: [],
				worklist: [],
				loading: false,
				values: {},
				pages: {
					pageIndex: 2,
					pageSize: 20
				},
				tableHeight: parseFloat(window.innerHeight - 160),
				TypeIDList: [],
				DepartCodeList: [],
				fileList: [],
				clubDetailShow: false,
				text1: {},
				requestUrl: this.global.requestUrl,
				token: Cache.get('token'),
				teacherList: [],
				memberList: [],
				multipleSelection: [],
				FieldTypeList:[]
			};
		},
		computed: {},
		created() {
			this.getList();
			this.getOtherList();
		},
		methods: {
			async getList() {
				this.loading = true;
				let data = {};
				if (this.values) {
					data = this.values;
				}
				data.clubID = this.$route.query.ID;
				let res = this.typeCurrent===1?await ManageApplyClubFormList(data):await UserApplyClubFormList(data);
				this.loading = false;
				let d = res.data.data
				this.data = res.data.data
			},
			async getOtherList() {
				let res = await GetApplyFormFieldTypeList()
				this.FieldTypeList = res.data.data
			},
			addList() {
				this.text = {};
				this.addIf = !this.addIf;
			},
			modifyList(text) {
				this.text = {
					...text,
					time: new Date()
				};
				this.addIf = !this.addIf;
			},
			async sortList(text,type){
				// 1=向上 2=向下
				let data={}
				data.id = text.ID
				data.type = type
				let res = this.typeCurrent===1?await DoSortManageApplyClubForm(data):await DoSortUserApplyClubForm(data);
				if(res.data.code==0){
					this.getList();
					this.$message.success(res.data.msg)
				}else{
					this.$message.error(res.data.msg)
				}
			},
			deleteList(text) {
				let that = this;
				this.$confirm({
					title: '提示',
					content: `您确定删除该学生组织吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {};
						data.id = text.ID;
						let res = that.typeCurrent===1?await DoDeleteManageApplyClubForm(data):await DoDeleteUserApplyClubForm(data);
						if (res.data.code == 0) {
							that.getList();
							that.$message.success(res.data.msg);
						} else {
							that.$message.error(res.data.msg);
						}
					}
				});
			},
			closeFun(data) {
				this.addIf = false;
				this.clubDetailShow = false;
				if (data == 1) {
					this.getList();
				}
			}
		}
	};
</script>

<style lang="less" scoped>
	.home-form /deep/.ant-form-item {
		display: flex;
		margin-bottom: 10px !important;
	}

	.home-form /deep/.ant-form-item-label {
		width: 80px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		text-align: right;
	}

	.home-form /deep/.ant-form-item-control-wrapper {
		flex: 1;
	}

	/deep/.el-table th.is-leaf {
		background: #fafafa;
	}

	/deep/.el-table td,
	/deep/.el-table th {
		padding: 5px;
	}

	.option {
		margin-top: 0px;
		margin-bottom: 20px;
		overflow: hidden;

		.ant-btn {
			font-size: 12px;
		}
	}

	.foot {
		text-align: center;
		margin-top: 100px;
	}

	.el-pagination {
		margin-top: 10px;
	}
</style>
